package com.wengzw.controller;


import com.alibaba.fastjson.JSON;
import com.wengzw.po.User;
import com.wengzw.service.UserService;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.Map;
@CrossOrigin
@RestController
@RequestMapping("/user")
public class UserController {
    @Resource
    private UserService userService;

    @RequestMapping("/login")
    //接收到数据，调用service
    public String login(String user_name, String user_password, HttpSession session){
        // System.out.print("23333");
        //创建map集合保存信息
        Map<String,Object> map = new HashMap<String, Object>();
        //调用登陆方法
        User loginUser = userService.login(user_name,user_password);
        if(loginUser!=null){
            session.setAttribute("loginUser",loginUser);
            map.put("success",true);
        }else {
            map.put("success",false);
        }
        //将map集合的数据以json格式返回
        return JSON.toJSONString(map);
    }
}
